package com.weng.cloud.service8882.sleuth;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author: weng
 * @Date: 2022/3/12
 * @Description: com.weng.cloud.service8883.sleuth
 */
@RestController
public class SleuthController {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Value("${spring.application.name}")
    private String to;
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/testSleuth/{from}")
    public String testSleuth(@PathVariable String from){
        System.err.println("【提供方】"+from+" ---> 【消费方】"+to);
        String url = "http://weng-cloud-service-8883/testSleuth/"+to;
        return this.restTemplate.getForObject(url,String.class);
    }
}
